//
//  MemberSettingsController.m
//  myhuibao
//
//  Created by lijun on 13-3-7.
//  Copyright (c) 2013年 myhuibao. All rights reserved.
//

#import "MemberSettingsController.h"
#import <UIKit/UIKit.h>
#import "Config.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "SBJson.h"
#import<QuartzCore/QuartzCore.h>
#import "OMGToast.h"
#import "AppDelegate.h"
@interface MemberSettingsController()

@end
@implementation MemberSettingsController
@synthesize mainview;
@synthesize lbtitle;
@synthesize oldPwd;
@synthesize confPwd;
@synthesize lbname;
@synthesize lbconfPwd;
@synthesize lbnewPwd;
static int mdfType;//1:修改登录密码 2：修改支付密码 3：修改会员名称 4:修改会员昵称
@synthesize btsave;
@synthesize txnewPwd;
@synthesize mdview;
@synthesize mphoneId;
@synthesize exlabel1;
@synthesize exlabel2;
@synthesize exlabel3;
- (void)viewDidLoad
{
    [super viewDidLoad];
    mainview.hidden=YES;
    btsave.hidden=YES;
    [self showmdview];
    // Do any additional setup after loading the view, typically from a nib.
}
-(void) showmdview{
    NSString *mobile=@"";
    mobile=[mobile stringByAppendingString:[[Config Instance]getMobile]];
    mphoneId.text=@"头像";
    _lbName.text=[[Config Instance] getName];
    _lbNickName.text=[[Config Instance] getNickName];
    mdview.layer.cornerRadius=5;
    mdview.layer.borderWidth=1;
    mdview.layer.borderColor=LINE_COLOR.CGColor;
    [[mdview layer] setShadowOffset:CGSizeMake(1, 1)];
    [[mdview layer] setShadowRadius:1];
    [[mdview layer] setShadowOpacity:1];
    [[mdview layer] setShadowColor:LINE_COLOR.CGColor];
    oldPwd.delegate = self,txnewPwd.delegate =  self,confPwd.delegate=self;
    if(_strHeaderImage==nil)
    {
        _ImageView.image=[UIImage imageNamed:@"huang@2x.png"];
    }
    else
    {
        _ImageView.image=[UIImage imageWithContentsOfFile:_strHeaderImage];
    }

}

-(void) viewWillAppear:(BOOL)animated
{
   
}

-(void) showOld
{
    lbname.hidden = false;
    oldPwd.hidden = false;
    lbconfPwd.frame = CGRectMake(lbconfPwd.frame.origin.x, 160, lbconfPwd.frame.size.width,lbconfPwd.frame.size.height);
    confPwd.frame = CGRectMake(confPwd.frame.origin.x, 162, confPwd.frame.size.width,confPwd.frame.size.height);
    lbnewPwd.frame = CGRectMake(lbnewPwd.frame.origin.x, 110, lbnewPwd.frame.size.width,lbnewPwd.frame.size.height);
    txnewPwd.frame = CGRectMake(txnewPwd.frame.origin.x, 108, txnewPwd.frame.size.width,txnewPwd.frame.size.height);
    exlabel1.hidden = true;
}
-(void)hideOld
{
    lbname.hidden = true;
    oldPwd.hidden = true;
    lbconfPwd.frame = CGRectMake(lbconfPwd.frame.origin.x, 108, lbconfPwd.frame.size.width,lbconfPwd.frame.size.height);
    confPwd.frame = CGRectMake(confPwd.frame.origin.x, 108, confPwd.frame.size.width,confPwd.frame.size.height);
    lbnewPwd.frame = CGRectMake(lbnewPwd.frame.origin.x, 64, lbnewPwd.frame.size.width,lbnewPwd.frame.size.height);
    txnewPwd.frame = CGRectMake(txnewPwd.frame.origin.x, 64, txnewPwd.frame.size.width,txnewPwd.frame.size.height);
    exlabel1.hidden = true;
}
- (IBAction)mdfPayPwd:(id)sender {
    if([[Config Instance]getPayPassword]==NULL)
    {
        hasPayPassword = false;
        [self hideOld];
    }else
    {
        hasPayPassword = true;
        [self showOld];
    }    
    mainview.hidden=NO;
    lbtitle.text=@"修改积分密码";
    mdfType=2;
    lbname.text=@"原密码";
    oldPwd.placeholder=@"请输入原密码";
    oldPwd.secureTextEntry = true;
    lbconfPwd.hidden=NO;
    lbnewPwd.hidden=NO;
    txnewPwd.hidden=NO;
    txnewPwd.placeholder=@"输入六位数字";
    confPwd.hidden=NO;
    btsave.hidden=NO;
    exlabel1.hidden=NO;
    exlabel2.hidden=NO;
    exlabel3.hidden=NO;
    oldPwd.text=@"";
    txnewPwd.text=@"";
    confPwd.text=@"";
    mdview.hidden=YES;
    mainview.layer.cornerRadius=5;
    mainview.layer.borderWidth=1;
    mainview.layer.borderColor=LINE_COLOR.CGColor;
    [[mainview layer] setShadowOffset:CGSizeMake(1, 1)];
    [[mainview layer] setShadowRadius:1];
    [[mainview layer] setShadowOpacity:1];
    [[mainview layer] setShadowColor:LINE_COLOR.CGColor];

}

- (IBAction)goBack:(id)sender {
    //判断是不是主界面
    if ([lbtitle.text isEqualToString:@"title"]) {
        [super.navigationController
         popViewControllerAnimated:YES];
    }else{
        mainview.hidden=YES;
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭输入法，防止遮住下面的选项
        lbtitle.text=@"title";
        btsave.hidden=YES;
        mdview.hidden=NO;
    }
    
}

- (IBAction)mdfloginpwd:(id)sender {
    [self showOld];
    mainview.hidden=NO;
    lbtitle.text=@"修改登录密码";
    mdfType=1;
    lbname.text=@"原密码";
    oldPwd.placeholder=@"请输入原密码";
    oldPwd.secureTextEntry = true;
    oldPwd.text=@"";
    txnewPwd.text=@"";
    txnewPwd.placeholder=@"请输入6~16位的密码";
    confPwd.text=@"";
    lbconfPwd.hidden=NO;
    lbnewPwd.hidden=NO;
    txnewPwd.hidden=NO;
    confPwd.hidden=NO;
    btsave.hidden=NO;
    
    exlabel1.hidden=NO;
    exlabel2.hidden=NO;
    exlabel3.hidden=NO;
    mdview.hidden=YES;
    mainview.layer.cornerRadius=5;
    mainview.layer.borderWidth=1;
    mainview.layer.borderColor=LINE_COLOR.CGColor;
    [[mainview layer] setShadowOffset:CGSizeMake(1, 1)];
    [[mainview layer] setShadowRadius:1];
    [[mainview layer] setShadowOpacity:1];
    [[mainview layer] setShadowColor:LINE_COLOR.CGColor];
}



- (Boolean)checkpwd:(NSString *)string {
    Boolean b=false;
    if(mdfType==1){
        NSString *pPassword=string;
        //NSRegularExpression类里面调用表达的方法需要传递一个NSError的参数。下面定义一个
        NSRegularExpression *tNumRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[0-9]" options:NSRegularExpressionCaseInsensitive error:nil];
        //符合數字條件的有幾個字元
        int tNumMatchCount = [tNumRegularExpression numberOfMatchesInString:pPassword
                                                                    options:NSMatchingReportProgress
                                                                      range:NSMakeRange(0, pPassword.length)];
        
        
        
        //英文字條件d
        NSRegularExpression *tLetterRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[A-Za-z]" options:NSRegularExpressionCaseInsensitive error:nil];
        //符合英文字條件的有幾個字元
        int tLetterMatchCount = [tLetterRegularExpression numberOfMatchesInString:pPassword options:NSMatchingReportProgress range:NSMakeRange(0, pPassword.length)];
//        if (tNumMatchCount + tLetterMatchCount != pPassword.length||tNumMatchCount<1||tLetterMatchCount<1)
        //由6-16字母或数字组成
        if (tNumMatchCount + tLetterMatchCount != pPassword.length || pPassword.length<6 || pPassword.length>16)
        {
            b=true;
        }
    }else{
        NSString *pPassword=string;
        //NSRegularExpression类里面调用表达的方法需要传递一个NSError的参数。下面定义一个
        NSRegularExpression *tNumRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[0-9]" options:NSRegularExpressionCaseInsensitive error:nil];
        //符合數字條件的有幾個字元
        int tNumMatchCount = [tNumRegularExpression numberOfMatchesInString:pPassword
                                                                    options:NSMatchingReportProgress
                                                                      range:NSMakeRange(0, pPassword.length)];
       
        if (tNumMatchCount != pPassword.length)
        {
            b=true;
        }

    }
    return  b;

}
- (IBAction)doSave:(id)sender {
    if((mdfType==1||(mdfType==2&&hasPayPassword))&& oldPwd.text.length<1){
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                      message:@"原密码不能为空"
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
        txnewPwd.text=@"";
        confPwd.text=@"";
        return;
    }

    if((mdfType==1||mdfType==2)&&txnewPwd.text.length<1){
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                      message:@"请输入新密码"
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
        txnewPwd.text=@"";
        confPwd.text=@"";
        return;
    }
    if((mdfType==1||mdfType==2)&&confPwd.text.length<1){
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                      message:@"请重复输入新密码"
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
        confPwd.text=@"";
        return;
    }
    if((mdfType==1||mdfType==2)&&![txnewPwd.text isEqualToString:confPwd.text]){
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                      message:@"二次输入的密码不一致"
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
        txnewPwd.text=@"";
        confPwd.text=@"";
        return;
    }
    if(mdfType==1){
        if([self checkpwd:txnewPwd.text]){
            UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                          message:@"密码为6~16字母或数字组成"
                                                         delegate:nil
                                                cancelButtonTitle:@"确定"
                                                otherButtonTitles:nil];
            [alert show];
            txnewPwd.text=@"";
            confPwd.text=@"";
            return;
        }
    }
    if(mdfType==2){
        int lenght=txnewPwd.text.length;
        if([self checkpwd:txnewPwd.text]||lenght!=6){
            UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                          message:@"请输入六位数字的积分密码"
                                                         delegate:nil
                                                cancelButtonTitle:@"确定"
                                                otherButtonTitles:nil];
            [alert show];
            txnewPwd.text=@"";
            confPwd.text=@"";
            return;
            
        }
    }

    if (mdfType==4 || mdfType==3) {
        if(oldPwd.text.length>16)//修改会员昵称，如果长度超过16个字符，提示过长
        {
            UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                      message:@"您输入的昵称过长"
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
            [alert show];
            oldPwd.text=@"";
            return;
        }
        else if([[oldPwd.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@""])
        {
            UIAlertView*alert = [[UIAlertView alloc]initWithTitle:APP_TITLE
                                                          message:mdfType==3?@"您输入的姓名不能为空":@"您输入的昵称不能为空"
                                                         delegate:nil
                                                cancelButtonTitle:@"确定"
                                                otherButtonTitles:nil];
            [alert show];
            oldPwd.text=@"";
            return;
        }
    }
    int memberId = [[Config Instance] getMemberId];
    NSString *password=[[Config Instance] getPassword];
    NSURL *url=nil;
    if(mdfType==1){//修改登录密码
        url=[NSURL URLWithString:url_modloginPwd];
    }
    else if(mdfType==2) {//修改支付密码
        url=[NSURL URLWithString:url_modpayPwd];
    }else if (mdfType==3){//修改会员名称
        url=[NSURL URLWithString:url_modname];
    }
    else{//修改会员昵称
        url=[NSURL URLWithString:url_modnickname];
    }
    NSString *sid=[NSString stringWithFormat:@"%d",memberId];
    ASIFormDataRequest *request=
    [ASIFormDataRequest requestWithURL:url];
    if(mdfType==1){//修改登录密码
        [request setPostValue: oldPwd.text forKey:@"oldPWD"];
        [request setPostValue: txnewPwd.text forKey:@"member.password"];
    }
    else if(mdfType==2){//修改支付密码
        if (hasPayPassword)
            [request setPostValue: oldPwd.text forKey:@"oldPWD"];
        else
            [request setPostValue:@"123456" forKey:@"oldPWD"];
        [request setPostValue: txnewPwd.text forKey:@"member.payPassword"];
        [request setPostValue:password forKey:@"member.password"];
    }
    else if(mdfType==3){//修改会员名称
        [request setPostValue:password forKey:@"member.password"];
        [request setPostValue:oldPwd.text forKey:@"member.name"];
    }
    else{//修改会员昵称
        [request setPostValue:password forKey:@"member.password"];
        [request setPostValue:oldPwd.text forKey:@"member.nickName"];
    }
    [request setPostValue: sid
                   forKey:@"member.memberID"];
    [request setShouldAttemptPersistentConnection:NO];
    [request setDelegate: self];
    [request startAsynchronous];
    
}

//下面是两个代理函数,当数据请求成功时会调用requestFinished，请求失败时（如网络问题或服务器内部错误）会调用requestFailed
- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSString *jsonStr = [request responseString];
    NSLog(@"%@",jsonStr);
    NSDictionary *dic = [jsonStr JSONValue];
    NSString *data = [dic valueForKey:@"status"];
    if([data isEqualToString:@"ERROR"]){
        data=[dic valueForKey:@"log"];
    }else{
        data=[dic valueForKey:@"data"];
        if(mdfType==1){
            [[Config Instance] setMemberId:0];
//            NSString *md5= [[Config Instance] md5HexDigest:txnewPwd.text];
//            [[Config Instance] setPassword:md5];
//            [[Config Instance] setPassword:txnewPwd.text];
        }else if(mdfType==2){
            NSString *md5= [[Config Instance] md5HexDigest:txnewPwd.text];
            [[Config Instance] setPayPassword:md5];
        }else if (mdfType==3){
            [[Config Instance] setName:oldPwd.text];
            _lbName.text=oldPwd.text;
        }else {
            [[Config Instance] setNickName:oldPwd.text];
            _lbNickName.text=oldPwd.text;
        }
    }
    UIAlertView*alert =nil;
    if(mdfType==1){
        NSString *msg = data;
        if([[dic valueForKey:@"status"]isEqualToString:@"SUCCESS"])
            msg = @"密码修改成功，请使用新密码重新登录。";
        alert=[[UIAlertView alloc]initWithTitle:@"提示"
                                        message:msg
                                       delegate:nil
                              cancelButtonTitle:@"确定"
                              otherButtonTitles:nil];
//        ((UILabel*)[[alert subviews] objectAtIndex:1]).textAlignment = UITextAlignmentLeft;
        [alert show];
    }else if(mdfType==2){
        alert=[[UIAlertView alloc]initWithTitle:@"提示"
                                        message:data
                                       delegate:nil
                              cancelButtonTitle:@"确定"
                              otherButtonTitles:nil];
        [alert show];
    }else {
        if([[dic valueForKey:@"status"]isEqualToString:@"SUCCESS"]){
            data=@"修改成功";
        }else{
            data=@"修改失败";
        }
        alert=[[UIAlertView alloc]initWithTitle:@"提示"
                                        message:data
                                       delegate:nil
                              cancelButtonTitle:@"确定"
                              otherButtonTitles:nil];
        [alert show];
    }
    /*
     UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
     message:[data valueForKey:@"data"]
     delegate:nil
     cancelButtonTitle:@"确定"
     otherButtonTitles:nil];
     [alert show];
     [alert release];
     */
    if([[dic valueForKey:@"status"] isEqualToString:@"ERROR"]){
        oldPwd.text=@"";
        txnewPwd.text=@"";
        confPwd.text=@"";
    }else{
       // [self.navigationController popViewControllerAnimated:YES];
        [self goBack:nil];
    }
    
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"%@",error);
    if (error.code==net_failure_code) {
        [OMGToast showWithText:net_failure_msg bottomOffset:100];
    }

}

- (IBAction)mdfName:(id)sender {
    [self showOld];
    mainview.hidden=NO;
    lbtitle.text=@"修改姓名";
    mdfType=3;
    lbname.text=@"新姓名";
    oldPwd.placeholder=@"输入您新的姓名";
    oldPwd.secureTextEntry = false;
    oldPwd.keyboardType = UIKeyboardTypeDefault;
    lbconfPwd.hidden=YES;
    lbnewPwd.hidden=YES;
    txnewPwd.hidden=YES;
    confPwd.hidden=YES;
    oldPwd.text=@"";
    btsave.hidden=NO;
    exlabel1.hidden=YES;
    exlabel2.hidden=YES;
    exlabel3.hidden=YES;
    mdview.hidden=YES;
    mainview.layer.cornerRadius=5;
    mainview.layer.borderWidth=1;
    mainview.layer.borderColor=LINE_COLOR.CGColor;
    [[mainview layer] setShadowOffset:CGSizeMake(1, 1)];
    [[mainview layer] setShadowRadius:1];
    [[mainview layer] setShadowOpacity:1];
    [[mainview layer] setShadowColor:LINE_COLOR.CGColor];
}

- (IBAction)mdfNickName:(id)sender {
    [self showOld];
    mainview.hidden=NO;
    lbtitle.text=@"修改昵称";
    mdfType=4;
    lbname.text=@"新昵称";
    oldPwd.placeholder=@"输入您新的昵称";
    oldPwd.secureTextEntry = false;
    oldPwd.keyboardType = UIKeyboardTypeDefault;
    lbconfPwd.hidden=YES;
    lbnewPwd.hidden=YES;
    txnewPwd.hidden=YES;
    confPwd.hidden=YES;
    oldPwd.text=@"";
    btsave.hidden=NO;
    exlabel1.hidden=YES;
    exlabel2.hidden=YES;
    exlabel3.hidden=YES;
    mdview.hidden=YES;
    mainview.layer.cornerRadius=5;
    mainview.layer.borderWidth=1;
    mainview.layer.borderColor=LINE_COLOR.CGColor;
    [[mainview layer] setShadowOffset:CGSizeMake(1, 1)];
    [[mainview layer] setShadowRadius:1];
    [[mainview layer] setShadowOpacity:1];
    [[mainview layer] setShadowColor:LINE_COLOR.CGColor];
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    //    if (theTextField == self.textField) {
    [theTextField resignFirstResponder];
    //    }
    return YES;
}
- (IBAction)OnUpdateHeader:(id)sender {
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择头像来源"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                         destructiveButtonTitle:nil
                                              otherButtonTitles:@"照相机", @"相册", nil];
    [sheet showInView:self.view];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    _ImageView.image=image;
    NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[@"Library/Caches/" stringByAppendingString:@"updateheader.jpg"]];
    [UIImageJPEGRepresentation(image,0.5) writeToFile:imagePath atomically:YES];
    NSURL *url = [NSURL URLWithString:url_updateheader];
    ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
    //    int memberId = [[Config Instance] getMemberId];
     [request setPostValue:[NSString stringWithFormat:@"%d",[[Config Instance] getMemberId]] forKey:@"member.memberID"];
    [request setPostValue:[[Config Instance] getPassword] forKey:@"member.password"];
    [request setFile:imagePath forKey:@"image"];
    [request setPostValue:@"updateheader.jpg" forKey:@"imageFileName"];
    [request buildRequestHeaders];
    [request setDidFinishSelector:@selector(UpdateFinish:)];
    request.delegate=self;
    [request startSynchronous];
    [self dismissModalViewControllerAnimated:YES];
    
}

- (void)UpdateFinish:(ASIHTTPRequest *)request
{
    NSString *jsonStr = [request responseString];
    NSDictionary *dic = [jsonStr JSONValue];
    if(![[dic valueForKey:@"status"] isEqualToString:@"SUCCESS"]){
        UIAlertView *view=[[UIAlertView alloc]initWithTitle:APP_TITLE message:[dic valueForKey:@"log"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [view show];
        return;
    }
    [OMGToast showWithText:[dic valueForKey:@"log"] bottomOffset:100];
    NSURL *url = [NSURL URLWithString:url_login];
    ASIFormDataRequest *req=[ASIFormDataRequest requestWithURL:url];
    [req setPostValue:[NSString stringWithFormat:@"%@",[[Config Instance] getMobile]]  forKey:@"member.mobile"];
    [req setPostValue: [[Config Instance] getLoginPass] forKey:@"member.password"];
    [req setShouldAttemptPersistentConnection:false];
    [req setDidFinishSelector:@selector(ReLoginFinish:)];
    [req setDelegate: self];
    [req startAsynchronous];
}

- (void)ReLoginFinish:(ASIHTTPRequest *)request
{
    NSString *jsonStr = [request responseString];
    //    NSLog(@"%@",jsonStr);
    NSDictionary *dic = [jsonStr JSONValue];
    
    NSDictionary *member = [dic valueForKey:@"data"];
    NSLog(@"%@", member);
    if(member == nil || (id)member == [NSNull null]){
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                      message:[dic valueForKey:@"log"]
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
        
    }else
    {
        [member setValue:[[Config Instance] getLoginPass] forKey:@"LoginPass"];
        [[Config Instance] saveLogin:member];
    }

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissModalViewControllerAnimated:YES];
    
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    UIImagePickerControllerSourceType sourceType;
    if(buttonIndex==0)
    {
        sourceType=UIImagePickerControllerSourceTypeCamera;
    }else if(buttonIndex==1)
    {
        sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    }else
    {
        return;
    }
    //    if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
    //        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    //    }
    //sourceType = UIImagePickerControllerSourceTypeCamera; //照相机
    //sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库
    //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
    picker.delegate = self;
    picker.allowsEditing = YES;//设置可编辑
    picker.sourceType = sourceType;
    [self presentModalViewController:picker animated:YES];//进入照相界面
}

@end
